﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Mall.Infrastructure.Repository
{
    /// <summary>
    /// 应用程序扩展
    /// </summary>
    public static class AppDomainExtensions
    {
        /// <summary>
        /// 获取工作单元
        /// </summary>
        /// <param name="app"></param>
        /// <returns></returns>
        public static IRepositoryContext GetRepositoryContext(this AppDomain app, string name = "")
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                var database= ConfigurationManager.AppSettings["DefaultDatabase"];
                if (database == null)
                {
                    throw new Exception("未配置默认数据库");
                }
                else
                {
                    return new EFRepositoryContext(ConfigurationManager.AppSettings["DefaultDatabase"].ToString());

                }
            }
            else
            {
                return new EFRepositoryContext(name);
            }
        }

    }
}
